package com.txc.common.global.config;

import com.txc.common.global.interceptor.TokenArgumentResolver;
import com.txc.common.global.interceptor.UserInfoInterceptor;
import com.txc.common.utils.jwt.TokenManager;
import com.txc.common.utils.middleware.RedisUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * @ClassName: MvcConfig
 * @Author: TXC
 * @Date: 2023-08-08 23:04
 **/
@Configuration
@ConditionalOnClass(DispatcherServlet.class)
public class MvcConfig implements WebMvcConfigurer {
    @Resource
    private RedisUtils redisUtils;

    @Resource
    private TokenManager tokenManager;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new UserInfoInterceptor(redisUtils, tokenManager));

    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(new TokenArgumentResolver(redisUtils, tokenManager));
    }
}
